home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / DB_CLIPP / 0411.ZIP / MOVE.C < prev    next >
Text File  |  1985-04-10  |  1KB  |  54 lines

  1. /*
  2.  * Program to move a file from one area to another.
  3.  */
  4. #include "stdio.h"
  5. main(argc,argv)
  6.     int argc;
  7.     char *argv[];
  8.     {
  9.     int c,
  10.         filesrc,
  11.         filetgt;
  12.     if (argc < 2)
  13.         {
  14.         printf("\n*** Missing Source Filename ***\n");
  15.         exit(1);
  16.         }
  17.     if (argc < 3)
  18.         {
  19.         printf("\n*** Missing Target Filename ***\n");
  20.         printf("Cannot move source to source\n");
  21.         exit(2);
  22.         }
  23.     printf("\nMoving %s to %s\n",argv[1],argv[2]);
  24.     if ((filesrc = open(argv[1],0)) == -1)
  25.         {
  26.         printf("\n*** Cannot open %s ***",argv[1]);
  27.         exit(3);
  28.         }
  29.     if ((filetgt = open(argv[2],0)) != -1)
  30.         {
  31.         printf("\n*** File %s currently exists ***\n",argv[2]);
  32.         printf("\nDo you wish to proceed? ");
  33.         c = getchar();
  34.         printf("\n");
  35.         if ((c != 'y') && (c != 'Y'))
  36.             exit(4);
  37.         fclose(filetgt);
  38.         }
  39.     filetgt = creat(argv[2]);
  40.     while ((c = fgetc(filesrc)) != EOF)
  41.         fputc(c,filetgt);
  42.     if ((c = fclose(filetgt)) == -1)
  43.         {
  44.         printf("\n*** Cannot close target file %s ***\n",argv[2]);
  45.         exit(5);
  46.         }
  47.     if ((c = unlink(argv[1])) == -1)
  48.         {
  49.         printf("\n*** Cannot delete source file %s ***\n",argv[1]);
  50.         exit(6);
  51.         }
  52.     printf("\nFile %s moved to %s\n",argv[1],argv[2]);
  53.     }
  54.